package cn.xizikelif.basic.service.impl;

import cn.xizikelif.basic.service.IVerifyCodeService;
import cn.xizikelif.basic.util.Base64Util;
import cn.xizikelif.basic.util.StrUtils;
import cn.xizikelif.basic.util.VerifyCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class VerifyCodeImageServiceImpl implements IVerifyCodeService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public String garph(String imageCodeKey) {
        //1.调用工具类方法获取四位随机数图片
        String code = StrUtils.getComplexRandomString(4);
        //2.随机数设置放进 redis中，
        redisTemplate.opsForValue().set(imageCodeKey,code, 5, TimeUnit.MINUTES);
        // 3.将code生成的 随机数生成图片，并编码成baes64
        String base64 = VerifyCodeUtils.VerifyCode(100,50,code);
        return base64;
    }
}
